
import com.obscure.delib.*;


public class GuiElement implements GuiElementAbstract {
	private deSprite m_sprite;
	private deAnimationObject m_animation;
	private int m_FrameClicked =0;
	private int m_FrameHover   =0;
	private int m_guiPosX = 0;
	private int m_guiPosY = 0;
	private int m_guiHeight = 42;
	private int m_guiWidth  = 195;
	private int m_guiID;
	
	public GuiElement(deSprite v_sprite)
	{
		setSprite(v_sprite);
		m_sprite.setAnim(0);
		
		m_animation = new deAnimationObject(v_sprite,0,0);
	}
	public void setSprite(deSprite m_sprite) {
		this.m_sprite = m_sprite;
	}
	@Override
	public void setPos(int vx,int vy)
	{
		m_guiPosX=vx;
		m_guiPosY=vy;
		m_animation.setPosX(m_guiPosX);
		m_animation.setPosY(m_guiPosY);
		m_animation.setPaintFrameWhenAnimFinish(true);
		m_animation.setAnimLoop(0);
	}
	
	public void setAnim(int animID)
	{
		m_sprite.setAnim(animID);
		m_animation.setAnimIndex(animID);
	}
	
	public void render()
	{
		m_animation.render();
	}
	@Override
	public boolean isIntersect(int posx,int posy)
	{
		if((posx>m_guiPosX && posx < m_guiPosX+m_guiWidth) && 
		   (posy>(m_guiPosY-m_guiHeight) && posy < (m_guiPosY)))
		{
			m_animation.setAnimLoop(1);
			return true;
		}
		return false;
	}
	public void setGuiID(int m_guiID) {
		this.m_guiID = m_guiID;
	}
	public int getGuiID() {
		return m_guiID;
	}

	public void setFrameClicked(int m_FrameClicked) {
		this.m_FrameClicked = m_FrameClicked;
	}
	public int getFrameClicked() {
		return m_FrameClicked;
	}
	public void setFrameHover(int m_FrameHover) {
		this.m_FrameHover = m_FrameHover;
	}
	public int getFrameHover() {
		return m_FrameHover;
	}
	// for clickable area
	public void setGUIWidthHight(int width,int height) {
		this.m_guiWidth  = width;
		this.m_guiHeight = height;
	}
	@Override
	public void justTouched() {
		m_animation.setFrameWhenAnimFinish(1);
	}
	@Override
	public void justTouchedReleased() {
		m_animation.setFrameWhenAnimFinish(0);
		
	}
	@Override
	public int getWidth() {
		// TODO Auto-generated method stub
		return this.m_guiWidth;
	}
	@Override
	public int getHeight() {
		// TODO Auto-generated method stub
		return this.m_guiHeight;
	}
}
